﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
[assembly: WebResource("Microsoft.Live.ServerControls.VE.VEMap.png", "image/png")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.VEDashboard.png", "image/png")]
namespace Microsoft.Live.ServerControls.VE
{
    public sealed class MapDesigner : ControlDesigner
    {

        #region Private Instance Field(s)

        private Map map = null;

        #endregion

        #region Public Instance Method(s)

        /// <summary>
        /// 
        /// </summary>
        /// <param name="component"></param>
        public override void Initialize(IComponent component)
        {
            map = component as Map;

            if (component == null)
                throw new InvalidOperationException();

            base.Initialize(component);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string GetDesignTimeHtml()
        {
            StringBuilder html = new StringBuilder();

            html.Append(@" <div style=");

            html.Append(@"""width:" + map.Width + ";height:" + map.Height + @";background: #808080 url(" + map.Page.ClientScript.GetWebResourceUrl(GetType(), "Microsoft.Live.ServerControls.VE.VEMap.png") + @") no-repeat center center;""> ");
            if (map.Dashboard && map.DashboardSize == DashboardSize.Normal)
            {
                int DashWidth = (map.Width.Value < 354) ? (int)map.Width.Value : 354;
                
                html.Append(@"<div style=");
                html.Append(@"""position:absolute;width:" + DashWidth + "px;height:136px;background: transparent url(" +
                            map.Page.ClientScript.GetWebResourceUrl(GetType(),
                                                                    "Microsoft.Live.ServerControls.VE.VEDashboard.png") +
                            @") no-repeat;""> ");
                html.Append(@"</div>");
            }
            html.Append(@"</div>");

            return html.ToString();
        }

        #endregion

    }
}
